#pragma once

namespace cge {
	class BinaryBuffer {
	public:
		typedef char*       iterator;
		typedef const char* const_iterator;
		typedef char        value_type;

		explicit BinaryBuffer( unsigned cap ): s_(0), c_(cap) {
			if( c_==0 )
				buf_ = 0;
			else
				buf_ = new char[c_];
		}

		~BinaryBuffer() {
			delete[] buf_;
		}

		iterator       begin()       { return buf_; }
		iterator       end()         { return buf_+s_; }
		const_iterator begin() const { return buf_; }
		const_iterator end()   const { return buf_+s_; }
		
		bool     empty()    const { return s_ == 0; }
		unsigned size()     const { return s_; }
		unsigned capacity() const { return c_; }

		void resize( unsigned size ) { s_ = size>c_?c_:size; }

		operator const char*() const { return buf_; }
		operator char*() { return buf_; }

	private:
		BinaryBuffer( const BinaryBuffer& );
		BinaryBuffer& operator=( const BinaryBuffer& );

		char*    buf_;
		unsigned s_,c_;
	};
}
